package com.hulk.dryad.common.constant.enums;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.EnumSet;

/**
 * 证件类型
 * @author hulk
 */
public enum CertificateType {

    ID("ID","CertificateType_ID");

    @Getter
    private String code;

    private String desc;

    CertificateType(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getDesc() {
        return messageSource.getMessage(desc, null, desc, LocaleContextHolder.getLocale());
    }


    private MessageSource messageSource;

    public CertificateType setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
        return this;
    }


    @Component
    public static class ReportTypeServiceInjector {

        @Autowired
        private MessageSource messageSource;

        @PostConstruct
        public void postConstruct() {
            for (CertificateType ec : EnumSet.allOf(CertificateType.class)) {
                ec.setMessageSource(messageSource);
            }
        }
    }
}
